The American Equities investment company offers a wide range of investment opportunities ranging from mutual funds to bonds.
Investors can check the value of their portfolio from the American Equities’ web page.
Information about personal portfolios is protected via encryption and can only be accessed using a password.
The American Equities company requires that a password consist of 8 characters, 5 of which must be letters and the other 3 digits.
The letters and digits can be arranged in any order.
For example,

rt56AA7q
123actyN
1Lo0Dwa9
myNUM741
are all valid passwords.
However, the following are all invalid:
the476NEw // It contains more than 8 characters (also more than 5 letters)
be68moon // It contains less than 3 digits.
$retrn99 // It contains only 2 digits and has an invalid character (‘$’)
American Equities needs a program for their web page that determines whether or not an entered password is valid.

// This program tests a password for the American Equities
// web page to see if the format is correct
// Place Your Name Here
#include 
#include 
#include 
using namespace std;
// function prototypes
bool testPassWord(char[]);
int countLetters(char *);
int countDigits(char *);
int main() {
    char passWord[20];
    cout << "Enter a password consisting of exactly 5 "
         << "letters and 3 digits:" << endl;
    cin.getline(passWord, 20);
    if (testPassWord(passWord))
        cout << "Please wait - your password is being verified" << endl;
    else {
        cout << "Invalid password. Please enter a password "
             << "with exactly 5 letters and 3 digits" << endl;
        cout << "For example, my37RuN9 is valid" << endl;
    }
    // Fill in the code that will call countLetters and
    // countDigits and will print to the screen both the number of
    // letters and digits contained in the password.
    return 0;
}
//**************************************************************
// testPassWord
//
// task: determines if the word in the
// character array passed to it, contains
// exactly 5 letters and 3 digits.
// data in: a word contained in a character array
// data returned: true if the word contains 5 letters & 3
// digits, false otherwise
//
//**************************************************************
bool testPassWord(char custPass[]) {
    int numLetters, numDigits, length;
    length = ...  // Use strlen() to determine length of string
        numLetters = countLetters(custPass);
    numDigits = countDigits(custPass);
    if (numLetters == 5 && numDigits == 3 && length == 8)
        return true;
    else
        return false;
}
//*******************************************************************
// countLetters
//
// task: This function counts the number of letters
// (both capital and lower case) in the string
// data in: pointer that points to an array of characters
// data returned: number of letters in the array of characters
//
//*******************************************************************
int countLetters(char *strPtr) {
    int occurs = 0;
    while (*strPtr != '\0')  // loop is executed as long as
    // the pointer strPtr does not point
    // to the null character which
    // marks the end of the string
    {
        if (...)  // Use isalpha() to determine if the character is a
            letter occurs++;
        strPtr++;
    }
    return occurs;
}
//*******************************************************************
// countDigits
//
// task: This function counts the number of digits
// in the string
// data in: pointer that points to an array of characters
// data returned: number of digits in the array of characters
//
//*******************************************************************
int countDigits(char *strPtr) {
    int occurs = 0;  // this keeps track how many times a digit occurs
    while (*strPtr != '\0') {
        if (...)  // Use isdigit() to determine if the character is a
            digit occurs++;
        strPtr++;
    }
    return occurs;
}

Exercise 1

Fill in the code at parts commented in bold and then run the program several times, testing with both valid and invalid passwords.
Read through the program and make sure you understand the logic of the code.


    


Exercise 2

Alter the program so that a valid password now consists of 10 characters, 6 of which must be digits and the other 4 letters.


    


Exercise 3

Adjust your program from Exercise 2 so that only lower case letters are allowed for valid passwords.


    


// This program shows how the toupper and tolower functions can be
// applied in a C++ program

#include 
#include 
#include 
using namespace std;
int main() {
    int week, total, dollars;
    float average;
    char choice;
    cout << showpoint << fixed << setprecision(2);
    do {
        total = 0;
        for (week = 1; week <= 4; week++) {
            cout << "How much (to the nearest dollar) did you"
                 << " spend on food during week " << week << " ?:" << endl;
            cin >> dollars;
            total = total + dollars;
        }
        average = total / 4.0;
        cout << "Your weekly food bill over the chosen month is $" << average << endl << endl;
        do {
            cout << "Would you like to find the average for "
                 << "another month?";
            cout << endl << "Enter Y or N" << endl;
            cin >> choice;
        } while (toupper(choice) != 'Y' && toupper(choice) != 'N');
    } while (toupper(choice) == 'Y');
    return 0;
}

Exercise 1

Run the program several times with various inputs.


    


Exercise 2

Notice the following do-while loop which appears near the end of the program:

do
{
cout << "Would you like to find the average for another month?";
cout << endl << "Enter Y or N" << endl;
cin >> choice;
} while(toupper(choice) != 'Y' && toupper(choice) != 'N');
How would the execution of the program be different if we removed this loop?
Try removing the loop but leave the following lines in the program:
cout << "Would you like to find the average for another month?";
cout << endl << "Enter Y or N" << endl;
cin >> choice;
Record what happens when you run the new version of the program.


    


Exercise 3

Alter program case_convert.cpp so that it performs the same task but uses tolower rather than toupper.


    


Exercise 1


    


Exercise 2


    


Exercise 3


    


Exercise 1


    


Exercise 2


    


Exercise 3


    


Exercise 1


    


Exercise 2


    


Exercise 3